﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Xml;
using System.Drawing.Drawing2D;
using Duoease.ContainerModel.Utils;
using System.Windows.Forms;
using SmartMD.DataModel;

namespace Duoease.ContainerModel.Entity
{
    public class BaseModel : IBaseModel
    {
        #region 属性
        public string ID = "";  //标识
        public string Name = "";
        public string ElementType; //元素类型
        public string TagName;   //构造xml时的标签名
        public Graphics g = null;  //画笔
        public Point Location = new Point();  //位置
        private int _containerWidth = 1;  //
        private int _containerHeight = 1;
        public int UnitWidth = 0;
        public int UnitHeight = 0;
        public int CanvasWidth = 0;  //画布的宽和高
        public int CanvasHeight = 0;
        public int Row = 1;
        public int Column = 1;
        public int Alpha = 100;
        public Color SurfaceColor = Color.Yellow;
        public Color LineColor = Color.Yellow;
        public int LineWidth = 1;
        public string Title = "";
        public Color BackGround = Color.White;
        public int Slope = 40;

        public int SpecimenCount = 0;
        public int Sum = 0;
        //容器视图控件
        public ContainerModelView View = null;
        //模型所在面板
        public SplitterPanel panel = null;
        /// <summary>
        /// 冰箱或者架子所有格存放比例
        /// </summary>
        public double[,] StoredPercent = null;
        /// <summary>
        /// 盒子所有格是否为空
        /// </summary>
        public bool[,] IsFull = null;

        public int ContainerWidth
        {
            get { return _containerWidth; }
            set
            {
                _containerWidth = value;
                if (this.TagName != null && this.TagName == "BoxModel")
                {
                    UnitWidth = 40;
                }
                else if (this.GetType() == typeof(HorizontalFridge))
                {
                    UnitWidth = _containerWidth / (Column + 1);
                }
                else
                {
                    UnitWidth = _containerWidth / (Column + 2);
                }

            }
        }

        public int ContainerHeight
        {
            get { return _containerHeight; }
            set
            {
                _containerHeight = value;
                if (this.TagName != null && this.TagName == "BoxModel")
                {
                    UnitHeight = 40;
                    Location.X = ContainerWidth / (Column + 2);
                    Location.Y = ContainerHeight * 3 / 5;
                }
                else if (this.GetType() == typeof(HorizontalFridge))
                {
                    UnitHeight = _containerHeight / (Row + 4);
                    Location.X = _containerWidth / (Column + 4);
                    Location.Y = _containerHeight / (Row + 1);
                }
                else
                {
                    UnitHeight = _containerHeight / (Row + 2);
                    Location.X = _containerWidth / (Column + 2);
                    Location.Y = _containerHeight / (Row + 2);
                }
            }
        }

        #endregion

        public string[,] tooltips;  //提示信息
        /**
         * 功能：刷新控件
         * 
         * */
        public virtual void Refresh()
        {
            this.View.leftlabel.Text = Name + ID;
            //label1.Font = new Font(label1.Font.FontFamily, 20, FontStyle.Bold);

            /*if (this.View.IsCreatNewModel)
            {

                this.View.docmodel.ConstructXml(this, ModelStyle.VerticalFridge, this.View.ctnNo);
            }*/
            if (this.View.FridgeWidth == 0 && this.View.FridgeHeight == 0)
            {
                this.View.FridgeWidth = 1;
                this.View.FridgeHeight = 1;
            }

            this.View.FridgeWidth = Convert.ToInt32(this.panel.Width);
            this.View.FridgeHeight = Convert.ToInt32(this.panel.Height);
        
            this.StoredPercent = new double[Row, Column]; //冰箱存放状态
            //GetModelPercent(this.TagName);

            AffixToLabel(View.leftlabel, this.View.FridgeWidth, this.View.FridgeHeight);
            this.panel.Refresh();
        }

        public virtual void Draw()
        {

        }
        /**
        * 功能：解析模型文件
        * */
        public virtual void ParseXml(XmlNode xn)
        {
            if (xn == null)
            {
                return;
            }
            this.ID = xn.Attributes["ID"].Value.ToString();
            this.UnitWidth = Convert.ToInt32(xn.Attributes["Width"].Value);
            this.UnitHeight = Convert.ToInt32(xn.Attributes["Height"].Value);
            this.Row = Convert.ToInt32(xn.Attributes["Row"].Value);
            this.Column = Convert.ToInt32(xn.Attributes["Column"].Value);
            this.Alpha = Convert.ToInt32(xn.Attributes["Alpha"].Value);
            this.SurfaceColor = Color.FromArgb(Convert.ToInt32(xn.Attributes["SurfaceColorR"].Value), Convert.ToInt32(xn.Attributes["SurfaceColorG"].Value), Convert.ToInt32(xn.Attributes["SurfaceColorB"].Value));
            this.LineColor = Color.FromArgb(Convert.ToInt32(xn.Attributes["LineColorR"].Value), Convert.ToInt32(xn.Attributes["LineColorG"].Value), Convert.ToInt32(xn.Attributes["LineColorB"].Value));
            this.LineWidth = Convert.ToInt32(xn.Attributes["LineWidth"].Value);
            this.Title = xn.Attributes["Title"].Value.ToString();
            this.SpecimenCount = Convert.ToInt32(xn.Attributes["SpecimenCount"].Value);
            this.Sum = Convert.ToInt32(xn.Attributes["Sum"].Value);
        }

        /**
        * 功能：构造模型文件
        * 
        * */
        public virtual XmlElement ConstructXml(XmlDocument doc, string tagName, XmlElement element)
        {
            //XmlDocument xmlDoc = new XmlDocument();
            XmlElement xe;
            if (element == null)
            {
                xe = doc.CreateElement(tagName);
            }
            else
            {
                xe = element;
            }
            xe.SetAttribute("ID", this.ID.ToString());
            xe.SetAttribute("Title", this.Title.ToString());
            xe.SetAttribute("Width", this.UnitWidth.ToString());
            xe.SetAttribute("Height", this.UnitHeight.ToString());
            xe.SetAttribute("Row", this.Row.ToString());
            xe.SetAttribute("Column", this.Column.ToString());

            xe.SetAttribute("Alpha", this.Alpha.ToString());
            xe.SetAttribute("SurfaceColorR", this.SurfaceColor.R.ToString());
            xe.SetAttribute("SurfaceColorG", this.SurfaceColor.G.ToString());
            xe.SetAttribute("SurfaceColorB", this.SurfaceColor.B.ToString());
            xe.SetAttribute("LineColorR", this.LineColor.R.ToString());
            xe.SetAttribute("LineColorG", this.LineColor.G.ToString());
            xe.SetAttribute("LineColorB", this.LineColor.B.ToString());
            xe.SetAttribute("LineWidth", this.LineWidth.ToString());
            xe.SetAttribute("SpecimenCount", this.SpecimenCount.ToString());
            xe.SetAttribute("Sum", this.Sum.ToString());

            return xe;
        }

        #region 绘制方法
        private void DrawSingleCube(Graphics g, Point location, int width, int height, int alpha, Color surfaceColor)
        {
            Point p2 = new Point(location.X + width, location.Y);
            Point p3 = new Point(location.X, location.Y + height);
            Point p4 = new Point(location.X + width, location.Y + height);
            Point p5 = new Point(location.X + this.Slope, location.Y - this.Slope);
            Point p6 = new Point(p5.X + width, p5.Y);
            Point p7 = new Point(p5.X, p5.Y + height);
            Point p8 = new Point(p6.X, p6.Y + height);

            PointF[] p = new PointF[4];
            Color baseColor = EdgeColor.GetRenderingColor(EdgeColorType.SurfaceColor, surfaceColor);
            GraphicsPath gp = new GraphicsPath();
            Pen pen = new Pen(this.LineColor, this.LineWidth);
            pen.DashStyle = DashStyle.DashDot;
            //左面
            p[0] = p5;
            p[1] = location;
            p[2] = p3;
            p[3] = p7;
            //g.DrawPolygon(pen, p);
            gp.AddLines(p);
            g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);

            //背面
            //if (!IsShell)
            {
                p[0] = p6;
                p[1] = p5;
                p[2] = p7;
                p[3] = p8;
                //g.DrawPolygon(pen, p);
                gp = new GraphicsPath();
                gp.AddLines(p);
                g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);
            }

            //if (cubeTopRow)
            {
                //顶面
                p[0] = p6;
                p[1] = p5;
                p[2] = location;
                p[3] = p2;
                //g.DrawPolygon(pen, p);
                gp = new GraphicsPath();
                gp.AddLines(p);
                g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);
            }


            //前面
            //if (!IsShell)
            {
                p[0] = p2;
                p[1] = location;
                p[2] = p3;
                p[3] = p4;
                //g.DrawPolygon(pen, p);
                gp = new GraphicsPath();
                gp.AddLines(p);
                g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);
            }

            //右面
            //if (cubeLastRow)
            //{
            //p[0] = p6;
            //p[1] = p2;
            //p[2] = p4;
            //p[3] = p8;
            ////g.DrawPolygon(new Pen(Brushes.Blue), p);
            //gp = new GraphicsPath();
            //gp.AddLines(p);
            //g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);
            //}

            //底面
            //if (!IsShell)
            {
                p[0] = p8;
                p[1] = p7;
                p[2] = p3;
                p[3] = p4;
                //g.DrawPolygon(pen, p);
                gp = new GraphicsPath();
                gp.AddLines(p);
                g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);
            }
        }

        public void Render(Graphics g, Point location, int width, int height, int alpha, Color surfaceColor)
        {
            Point p2 = new Point(location.X + width, location.Y);
            Point p3 = new Point(location.X, location.Y + height);
            Point p4 = new Point(location.X + width, location.Y + height);
            Point p5 = new Point(location.X + this.Slope, location.Y - this.Slope);
            Point p6 = new Point(p5.X + width, p5.Y);
            Point p7 = new Point(p5.X, p5.Y + height);
            Point p8 = new Point(p6.X, p6.Y + height);

            PointF[] p = new PointF[4];
            Color baseColor = EdgeColor.GetRenderingColor(EdgeColorType.SurfaceColor, surfaceColor);
            GraphicsPath gp = new GraphicsPath();
            Pen pen = new Pen(Color.Black, 1);

            //左面
            p[0] = p5;
            p[1] = location;
            p[2] = p3;
            p[3] = p7;
            g.DrawPolygon(pen, p);
            gp.AddLines(p);
            g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);

            //背面
            //if (!IsShell)
            {
                p[0] = p6;
                p[1] = p5;
                p[2] = p7;
                p[3] = p8;
                g.DrawPolygon(pen, p);
                gp = new GraphicsPath();
                gp.AddLines(p);
                g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);
            }

            //if (cubeTopRow)
            {
                //顶面
                p[0] = p6;
                p[1] = p5;
                p[2] = location;
                p[3] = p2;
                g.DrawPolygon(pen, p);
                gp = new GraphicsPath();
                gp.AddLines(p);
                g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);
            }


            //前面
            //if (!IsShell)
            {
                p[0] = p2;
                p[1] = location;
                p[2] = p3;
                p[3] = p4;
                g.DrawPolygon(pen, p);
                gp = new GraphicsPath();
                gp.AddLines(p);
                g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);
            }

            //右面
            //if (cubeLastRow)
            //{
            //p[0] = p6;
            //p[1] = p2;
            //p[2] = p4;
            //p[3] = p8;
            ////g.DrawPolygon(new Pen(Brushes.Blue), p);
            //gp = new GraphicsPath();
            //gp.AddLines(p);
            //g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);
            //}

            //底面
            //if (!IsShell)
            {
                p[0] = p8;
                p[1] = p7;
                p[2] = p3;
                p[3] = p4;
                g.DrawPolygon(pen, p);
                gp = new GraphicsPath();
                gp.AddLines(p);
                g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);
            }
        }

        private void DrawShell(Graphics g, Point location, int width, int height, int alpha, Color surfaceColor)
        {
            Point p2 = new Point(location.X + width, location.Y);
            Point p3 = new Point(location.X, location.Y + height);
            Point p4 = new Point(location.X + width, location.Y + height);
            Point p5 = new Point(location.X + this.Slope, location.Y - this.Slope);
            Point p6 = new Point(p5.X + width, p5.Y);
            Point p7 = new Point(p5.X, p5.Y + height);
            Point p8 = new Point(p6.X, p6.Y + height);

            PointF[] p = new PointF[4];
            GraphicsPath gp = new GraphicsPath();
            Color baseColor = EdgeColor.GetRenderingColor(EdgeColorType.SurfaceColor, surfaceColor);

            ////左面
            //p[0] = p5;
            //p[1] = location;
            //p[2] = p3;
            //p[3] = p7;
            ////g.DrawPolygon(pen, p);
            //gp.AddLines(p);
            //g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);          


            //顶面
            p[0] = p6;
            p[1] = p5;
            p[2] = location;
            p[3] = p2;
            //g.DrawPolygon(pen, p);
            gp = new GraphicsPath();
            gp.AddLines(p);
            g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);

            ////前面
            ////p[0] = p2;
            ////p[1] = location;
            ////p[2] = p3;
            ////p[3] = p4;
            ////g.DrawPolygon(new Pen(Brushes.Blue), p);
            ////gp = new GraphicsPath();
            ////gp.AddLines(p);
            ////g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);


            //右面
            //p[0] = p6;
            //p[1] = p2;
            //p[2] = p4;
            //p[3] = p8;
            ////g.DrawPolygon(pen, p);
            //gp = new GraphicsPath();
            //gp.AddLines(p);
            //g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);


            ////底面
            //p[0] = p8;
            //p[1] = p7;
            //p[2] = p3;
            //p[3] = p4;
            //g.DrawPolygon(pen, p);
            //gp = new GraphicsPath();
            //gp.AddLines(p);
            //g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);

            ////背面
            //p[0] = p6;
            //p[1] = p5;
            //p[2] = p7;
            //p[3] = p8;
            //pen.DashStyle = DashStyle.DashDot;
            //g.DrawPolygon(pen, p);
            //gp = new GraphicsPath();
            //gp.AddLines(p);
            //g.FillPath(new SolidBrush(Color.FromArgb(alpha, baseColor)), gp);   
        }

        private void DrawLine(Graphics g, Point location, int row, int column, int width, int height, Color lineColor, int lineWidth)
        {
            Point p2 = new Point(location.X + width, location.Y);
            Point p3 = new Point(location.X, location.Y + height);
            Point p4 = new Point(location.X + width, location.Y + height);
            Point p5 = new Point(location.X + this.Slope, location.Y - this.Slope);
            Point p6 = new Point(p5.X + width, p5.Y);
            Point p7 = new Point(p5.X, p5.Y + height);
            Point p8 = new Point(p6.X, p6.Y + height);

            lineColor = EdgeColor.GetRenderingColor(EdgeColorType.DarkerThanSurface, lineColor);
            Pen pen = new Pen(lineColor, lineWidth);
            g.DrawLine(pen, location, p2);
            g.DrawLine(pen, p2, p4);
            g.DrawLine(pen, p4, p3);
            g.DrawLine(pen, p3, location);
            g.DrawLine(pen, location, p5);
            g.DrawLine(pen, p5, p6);
            g.DrawLine(pen, p6, p2);
            g.DrawLine(pen, p6, p8);
            g.DrawLine(pen, p8, p4);

            Point lineFirst = new Point();
            Point lineLast = new Point();
            Pen pen_dot = new Pen(lineColor, lineWidth);
            pen_dot.DashStyle = DashStyle.DashDot;

            //if (row > 1)
            {
                for (int i = 0; i < row; i++)
                {
                    lineFirst = new Point(location.X, location.Y + i * height / row);
                    lineLast = new Point(p2.X, location.Y + i * height / row);
                    g.DrawLine(pen, lineFirst, lineLast);
                }
            }
            //if (column > 1)
            {
                for (int i = 0; i < column; i++)
                {
                    lineFirst = new Point(location.X + i * width / column, location.Y);
                    lineLast = new Point(p3.X + i * width / column, p3.Y);
                    g.DrawLine(pen, lineFirst, lineLast);
                }
            }

            //if (row > 1)
            {
                for (int i = 0; i <= row; i++)
                {
                    lineFirst = new Point(p5.X, p5.Y + i * height / row);
                    lineLast = new Point(p6.X, p5.Y + i * height / row);
                    g.DrawLine(pen_dot, lineFirst, lineLast);
                }
            }
            //if (column > 1)
            {
                for (int i = 0; i < column; i++)
                {
                    lineFirst = new Point(p5.X + i * width / column, p5.Y);
                    lineLast = new Point(p7.X + i * width / column, p7.Y);
                    g.DrawLine(pen_dot, lineFirst, lineLast);
                }
            }
            for (int i = 0; i <= row; i++)
            {
                for (int j = 0; j <= column; j++)
                {
                    lineFirst = new Point(location.X + j * width / column, location.Y + i * height / row);
                    lineLast = new Point(p5.X + j * width / column, p5.Y + i * height / row);
                    g.DrawLine(pen_dot, lineFirst, lineLast);
                }
            }
        }

        private void DrawBoxLine(Graphics g, Point location, int row, int column, int width, int height, Color lineColor, int lineWidth)
        {
            Point p2 = new Point(location.X + width * column, location.Y);
            Point p3 = new Point(location.X, location.Y + height);
            Point p4 = new Point(p2.X, p2.Y + height);
            Point p5 = new Point(location.X + row * this.Slope, location.Y - row * this.Slope);
            Point p6 = new Point(p5.X + width * column, p5.Y);
            Point p7 = new Point(p5.X, p5.Y + height);
            Point p8 = new Point(p6.X, p6.Y + height);

            lineColor = EdgeColor.GetRenderingColor(EdgeColorType.DarkerThanSurface, lineColor);
            Pen pen = new Pen(lineColor, lineWidth);
            //g.DrawLine(pen, location, p2);
            //g.DrawLine(pen, p2, p4);
            g.DrawLine(pen, p4, p3);
            //g.DrawLine(pen, p3, location);
            //g.DrawLine(pen, location, p5);
            //g.DrawLine(pen, p5, p6);
            //g.DrawLine(pen, p6, p2);
            //g.DrawLine(pen, p6, p8);
            g.DrawLine(pen, p8, p4);

            Point lineFirst = new Point();
            Point lineLast = new Point();
            Pen pen_dot = new Pen(lineColor, lineWidth);
            pen_dot.DashStyle = DashStyle.DashDot;

            //PointF[] p = new PointF[4];
            //p[0] = location;
            //p[1] = p2;
            //p[2] = p3;
            //p[3] = p4;
            //g.DrawPolygon(pen, p);

            //if (row > 1)
            {
                for (int i = 0; i <= row; i++)
                {
                    lineFirst = new Point(location.X + i * this.Slope, location.Y - i * this.Slope);
                    lineLast = new Point(p2.X + i * this.Slope, lineFirst.Y);
                    g.DrawLine(pen, lineFirst, lineLast);

                    lineFirst = new Point(p2.X + i * this.Slope, lineFirst.Y);
                    lineLast = new Point(lineFirst.X, lineFirst.Y + height);
                    g.DrawLine(pen, lineFirst, lineLast);
                }
            }
            //if (column > 1)
            {
                for (int i = 0; i <= column; i++)
                {
                    lineFirst = new Point(location.X + i * width, location.Y);
                    lineLast = new Point(p5.X + i * width, p5.Y);
                    g.DrawLine(pen, lineFirst, lineLast);

                    lineFirst = new Point(location.X + i * width, location.Y);
                    lineLast = new Point(lineFirst.X, lineFirst.Y + height);
                    g.DrawLine(pen, lineFirst, lineLast);
                }
            }

            ////if (row > 1)
            //{
            //    for (int i = 0; i <= row; i++)
            //    {
            //        lineFirst = new Point(p5.X, p5.Y + i * height / row);
            //        lineLast = new Point(p6.X, p5.Y + i * height / row);
            //        g.DrawLine(pen_dot, lineFirst, lineLast);
            //    }
            //}
            ////if (column > 1)
            //{
            //    for (int i = 0; i < column; i++)
            //    {
            //        lineFirst = new Point(p5.X + i * width / column, p5.Y);
            //        lineLast = new Point(p7.X + i * width / column, p7.Y);
            //        g.DrawLine(pen_dot, lineFirst, lineLast);
            //    }
            //}
            //for (int i = 0; i <= row; i++)
            //{
            //    for (int j = 0; j <= column; j++)
            //    {
            //        lineFirst = new Point(location.X + j * width / column, location.Y + i * height / row);
            //        lineLast = new Point(p5.X + j * width / column, p5.Y + i * height / row);
            //        g.DrawLine(pen_dot, lineFirst, lineLast);
            //    }
            //}
        }

        private void DrawFullState(Graphics g, Point location, int width, int height, double percent)
        {
            if (percent > 1)
                percent = 1;
            int FullState = (int)(percent * height);
            Rectangle rect = new Rectangle(new Point(location.X, (int)(location.Y + height - percent * height)), new Size(width, FullState));
            g.DrawRectangle(new Pen(Color.Blue), rect);
            g.FillRectangle(new SolidBrush(Color.FromArgb(255, Color.DeepPink)), rect);
        }

        public void JoinIceModel(Graphics g, Point location, int row, int column, int width, int height, int alpha, Color surfaceColor, Color lineColor, int lineWidth)
        {
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < column; j++)
                {
                    DrawSingleCube(g, new Point(location.X + width * j, location.Y + height * i), width, height, alpha, surfaceColor);
                    //DrawFullState(g, new Point(location.X + width * j, location.Y + height * i), width, height);   
                }
            }

            if (this.StoredPercent != null && StoredPercent.Length == row * column)
            {
                for (int i = 0; i < Row; i++)
                {
                    for (int j = 0; j < column; j++)
                    {
                        DrawFullState(g, new Point(location.X + width * j, location.Y + height * i), width, height, StoredPercent[i, j]);
                    }
                }
            }
            //DrawCube(g, location, width * column, height * row, alpha, baseColor,true);
            //DrawShell(g, location, width * column, height * row, alpha, surfaceColor);
            DrawLine(g, location, row, column, width * column, height * row, lineColor, lineWidth);

        }

        public void JoinBoxModel(Graphics g, Point location, int row, int column, int width, int height, int alpha, Color surfaceColor, Color lineColor, int lineWidth)
        {
            this.Slope = width / 2;
            for (int i = 0; i < row; i++)
            {
                for (int j = 0; j < column; j++)
                {
                    DrawSingleCube(g, new Point(location.X + this.Slope * i + width * j, location.Y - this.Slope * i), width, height, alpha, surfaceColor);
                }
            }
            if (IsFull != null && IsFull.Length == row * column)
            {
                Point origin = new Point(Location.X + (row - 1) * this.Slope, Location.Y - (row - 1) * this.Slope);
                PointF[] pf = new PointF[4];
                GraphicsPath gp = new GraphicsPath();
                Point p1 = location;
                Point p2 = new Point();
                Point p3 = new Point();
                Point p4 = new Point();

                for (int i = 0; i < row; i++)
                {
                    for (int j = 0; j < column; j++)
                    {
                        gp = new GraphicsPath();
                        p1 = new Point(origin.X + j * width - i * this.Slope, origin.Y + i * this.Slope);
                        p2 = new Point(p1.X + width, p1.Y);
                        p3 = new Point(p1.X + this.Slope, p1.Y - this.Slope);
                        p4 = new Point(p3.X + width, p3.Y);

                        pf[0] = p4;
                        pf[1] = p3;
                        pf[2] = p1;
                        pf[3] = p2;
                        gp.AddLines(pf);
                        if (IsFull[i, j])
                        {
                            g.FillPath(new SolidBrush(Color.FromArgb(255, Color.DeepPink)), gp);
                        }
                        else
                        {
                            g.FillPath(new SolidBrush(Color.FromArgb(255, Color.White)), gp);
                        }

                    }
                }
            }
            //DrawCube(g, location, width * column, height * row, alpha, baseColor,true);
            //DrawShell(g, location, width * column, height * row, alpha, surfaceColor);
            DrawBoxLine(g, location, row, column, width, height, lineColor, lineWidth);
        }

        #endregion

        public virtual void AffixToLabel(Label oldLabel, int width, int height)
        {
            
        }

        /**
         * 功能：刷新标签
         * 
         * */
        public void RefreshLabel(string title)
        {
            Label label = new Label();
            label.Text = title;
            this.panel.Controls.Clear();
            this.panel.Controls.Add(label);
            this.panel.Refresh();
        }

        /**
         * 功能：鼠标点击事件
         * 
         * */
       
        public virtual void OnMouseClickHandler(object sender, MouseEventArgs e)
        { 
        }
        /**
         * 功能：鼠标moveover事件
         * 
         * */
        public virtual void OnMouseOverHandler(object sender, MouseEventArgs e)
        {
            Point p = new Point(e.X, e.Y);
            int x = 0;
            int y = 0;
            Point origin = Location;
            g = this.panel.CreateGraphics();

            if (e.X >= origin.X && e.X <= origin.X + UnitWidth * Column && e.Y >= origin.Y && e.Y <= origin.Y + UnitHeight * Row)
            {
                for (int i = 0; i < Column; i++)
                {
                    if (p.X >= origin.X + i * UnitWidth && p.X <= origin.X + (i + 1) * UnitWidth)
                    {
                        x = i + 1;
                        break;
                    }
                }
                for (int i = 0; i < Row; i++)
                {
                    if (p.Y >= origin.Y + i * UnitHeight && p.Y <= origin.Y + (i + 1) * UnitHeight)
                    {
                        y = i + 1;
                        break;
                    }
                }

                this.View.mouseTip.SetToolTip(this.panel.Controls.Owner, Title);
            }
            else
            {
                this.View.mouseTip.RemoveAll();
            }
        }
    }
}
